import { ref } from 'vue';
import { deletePaymentCardApi } from '@/api/sj/financialManagement/paymentCard/index'

const useAddPaymentCard = () => {

    const addVisible = ref(false);

    /** 打开 新增选项卡 弹窗 */
    const handlOpenAdd = async (row: any) => {
        addVisible.value = true;
    };

    /** 关闭 选项卡 弹窗 */
    const handlOpenAddClose = () => {
        addVisible.value = false;
    };

    /** 删除收款卡 */
    const handleDelete = async (row: any, fn: Function) => {
        ElMessageBox.confirm(
            '您确定要别除掉这张银行卡嘛，删除后不能用此卡进行付款或内部转账等操作，但是之前的支出/收入记录仍会保留',
            '提示',
            {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true,
            }
        )
            .then(async () => {

                try {
                    const { code } = await deletePaymentCardApi(row.id);
                    if (code == 200) {
                        ElMessage({
                            type: 'success',
                            message: '删除成功',
                        });
                        fn();
                    }
                } catch (error) {

                }

            })
            .catch(() => {

            })
    };

    return {
        addVisible,
        handlOpenAdd,
        handlOpenAddClose,
        handleDelete
    }
};

export default useAddPaymentCard;
